Low synchronization means of scheduler finalization

ABSTRACT

Shutting down a computer work scheduler. The work scheduler includes a number of virtual processors, each of which is either active or inactive. An active processor executes work, searches for work, or is idle. An inactive has no context running atop it. The method includes determining that all processors controlled by the scheduler are idle. As a result of determining that all controlled by the scheduler are idle, the method proceeds to a first phase of a shutdown operation, which when successful, includes: performing a sweep of all collections searching for any work in the scheduler and determining that no work is found in the scheduler. As a result of determining that no work is found in the scheduler, the method proceeds to a second phase of a shutdown operation, which when successful includes messaging all contexts in the scheduler and telling them to exit.

BACKGROUND Background and Relevant Art

Computers and computing systems have affected nearly every aspect ofmodern living. Computers are generally involved in work, recreation,healthcare, transportation, entertainment, household management, etc.

Modern computing systems often include multiple processor, multiple coreand/or multiple thread architectures. This allows the systems tosimultaneously perform different tasks among the different processors.Thus, different portions of a computing operation can be performed bydifferent threads within the same system.

Work schedulers can be used to assign work to different threads. Workschedulers can implement a number of different virtual processors andcan assign work to the different virtual processors to facilitate thework being accomplished. Work is defined as some computing task.

Some work schedulers, such as the ConcRT scheduler available fromMicrosoft Corporation of Redmond Wash., have semantics such that oncethey are released by the user, they shut down and finalize after allwork queued to the schedulers is completed. Unfortunately, counting workwithin the scheduler may be prohibitively expensive due to thesignificant cache line contention it would generate. Illustratively,assignment of each work task would need to include an operation toincrement a counter implemented on a shared cache line. To increment thecounter, the cache line would need to be locked out by the threadincrementing the counter from other threads. In software transactionalsystem, other threads that needed to increment the counter, would bestuck waiting for the lock to be released before they could incrementthe counter and begin the work. In hardware based transactional systems,concurrent attempts to access the cache line may result in large numberstransaction failures and cache line invalidations.

Because many different threads within the scheduler add and remove workfrom a variety of different collections, a hierarchical count of worksuffers the same type of problems.

The subject matter claimed herein is not limited to embodiments thatsolve any disadvantages or that operate only in environments such asthose described above. Rather, this background is only provided toillustrate one exemplary technology area where some embodimentsdescribed herein may be practiced.

BRIEF SUMMARY

One illustrative embodiment includes a method that may be practiced in acomputing system. The method includes acts for shutting down a computerwork scheduler. The work scheduler includes a number of virtualprocessors, each representing the ability to execute a single thread.Each virtual processor is either active or inactive. An active processorhas a context running atop it performing at least one of executing work,searching for work, or being idle after not finding work after apredetermined amount of searching for work. An inactive processor has nocontext running atop it.

The method includes determining that all processors in a given set ofactive virtual processors controlled by the scheduler are idle. As aresult of determining that all processors in the given set of activevirtual processors controlled by the scheduler are idle, the methodproceeds to a first phase of a shutdown operation, which whensuccessful, includes: performing a sweep of all collections searchingfor any work in the scheduler and determining that no work is found inthe scheduler. As a result of determining that no work is found in thescheduler, the method proceeds to a second phase of a shutdownoperation, which when successful includes messaging all contexts in thescheduler and telling them to exit.

This Summary is provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used as an aid in determining the scope of the claimed subjectmatter.

Additional features and advantages will be set forth in the descriptionwhich follows, and in part will be obvious from the description, or maybe learned by the practice of the teachings herein. Features andadvantages of the invention may be realized and obtained by means of theinstruments and combinations particularly pointed out in the appendedclaims. Features of the present invention will become more fullyapparent from the following description and appended claims, or may belearned by the practice of the invention as set forth hereinafter.

BRIEF DESCRIPTION OF THE DRAWINGS

To describe the manner in which the above-recited and other advantagesand features can be obtained, a more particular description of thesubject matter briefly described above will be rendered by reference tospecific embodiments which are illustrated in the appended drawings.Understanding that these drawings depict only typical embodiments andare not therefore to be considered to be limiting in scope, embodimentswill be described and explained with additional specificity and detailthrough the use of the accompanying drawings in which:

FIG. 1 illustrates a work scheduler;

FIG. 2 illustrates a state transition diagram;

FIG. 3 illustrates a method of shutting down a scheduler; and

FIG. 4 illustrates various virtual processor management actions.

DETAILED DESCRIPTION

Some embodiments described herein include functionality for shuttingdown a work scheduler. Embodiments include functionality whereby ascheduler effectively watches for each virtual processor in thescheduler which is performing work or searching for work to become idle.A virtual processor becoming idle is an indication that it cannot findwork. Once all virtual processors have become idle, the changing ofprocessor state to active, either from idle or inactive, of virtualprocessors is gated such that the shutting down can be aborted androlled back if needed. The scheduler ensures that no more work exists inany scheduler collection. If such can be verified, while all activeprocessors are idle, finalization of the shutdown begins. Otherwise,shutdown is rolled back until the next time that all virtual processorsbecome idle.

Some embodiments include functionality for using idle detection on acollection of a completely independent set of virtual processors as ameans of detecting when to start finalization. Embodiments may includemultiple phase shutdown with rollback, where the rollback is either dueto finding work or virtual processors being resurrected from idle orinactive states to perform new work in the scheduler. Resurrectionimplies that work was found. As used herein resurrection happens when areference count (which will be described in more detail below) of thescheduler falls to zero, thus starting the attempt to finalize, and thensome context unblocks and starts up. That context increments thereference count of the scheduler to pass it to another thread. Someembodiments may include a virtual processor gate mechanism andtransition semaphore, with state bits in a machine word to guaranteeatomic transitions. Some embodiments may use a sweep mechanism afteridle detection to determine whether to proceed with finalization.

Illustrative embodiments will now be illustrated. Referring now to FIG.1, a scheduler 100 is illustrated. The scheduler 100 is a referencecounted object that an external client can manipulate, such as forexample, through standard Reference/Release application programminginterfaces (APIs). The scheduler 100 includes a reference count 102. Thereference count, in this example, stores a count defining a number ofexternal clients that have called and are presently using the scheduler100. In the illustrated embodiment, when the reference count 102 of thescheduler falls to zero, the scheduler begins a shutdown process, thatwhen successful, finishes executing all the work assigned to it, shutsitself down (sometimes this process is referred to herein asfinalization), and optionally notifies the users/clients that havecalled the scheduler. In some embodiments, notification can occur as aresult of the user requesting to be notified.

The scheduler 100 itself contains a number of virtual processorsreferred to herein genetically as 104. Each virtual processor 104represents the ability to execute a single thread. A virtual processorexecuting a thread may be described as having a context running atop it.Virtual processors 104 can be either active or inactive. Active virtualprocessors have a context 106 running atop them which is eitherexecuting work, searching for work, or idle. A virtual processor 104 maytransition to an idle state if the virtual processor 104 cannot findwork to execute after repeated searching. Inactive virtual processorsare virtual processors which have yet to become active in that they haveno context running atop them.

Referring now to FIG. 2, a state diagram is shown illustratingtransitions of virtual processors. For convenience, FIG. 2 illustratesvirtual processors in one of three states. The three states include aninactive state 202, an active but idle state 204, and an active andnon-idle state 206. As noted previously, a virtual processor in theinactive state 202 is a virtual processor with no context running atopit. A processor in an active but idle state 204 is a processor that isnot actively performing work or searching for work, but is nonethelessrunning a context atop it and is available for work. A processor in anactive and non-idle state 206 is a processor that has a context runningatop it and is actively either performing work or searching for work.

When a given context executing atop a virtual processor finishesexecuting its assigned work item, it begins a process referred to assearch for work. It may go through all collections 108 in the schedulerin specific order and try to find a new work item to execute. Acollection 108 may be a member of collections (e.g., queues) of runnablecontexts or realized chores. A collection 108 may also or alternativelybe collections (e.g., work stealing queues) of tasks which may be stolento load balance parallel work. If a virtual processor 104 cannot findsuch a work item, the virtual processor 104 puts itself into, or is putinto by an external agent, a state 204 referred to as idle. Inparticular, the virtual processor 104 it is put to sleep until new workarrives in the scheduler 100, at which time the virtual processor 104 isawoken and is no longer idle, but is in the active a non-idle state 106.Conceptually, when the reference count 102 of the scheduler hits zeroand all active virtual processors 104 have become idle, the scheduler100 attempts to proceed into a first phase of shutdown.

To coordinate detection of idle, activation/removal of virtualprocessors via a dynamic resource manager, and awakening of idle virtualprocessors via work (e.g.: recently unblocked contexts), the scheduler'sinternal state maintains a shutdown gate 110. In the embodimentillustrated, the shutdown gate 110 is a single machine word. The lowerbits of the machine word (29 in this case) are the gate count 112. Inthis particular embodiment, this is the number of active virtualprocessors minus the number of idle virtual processors. The topmost 3bits of the machine word shutdown gate 110 are flags which are changedatomically with respect to the lower 29 bits.

When the scheduler reference count 102 falls to zero—indicating that theclient wants the scheduler to shutdown—the scheduler will atomically seta shutdown initiated flag 114 with a CAS (atomic compare-and-swap) loop.The CAS loop atomically compares the value of the machine word shutdowngate 110 at the beginning and end of the CAS loop, and if the compare isequal, then the shutdown initiated flag 114 is set. If the gate count112 is zero at the time the CAS succeeds, this indicates that there areno active virtual processors that are not idle. This means that novirtual processor within the scheduler was able to find work in anycollection. However, there may be work which will be scheduled at alater time (e.g.: blocked contexts that may be unblocked from anotherthread). These instances will be discussed later herein. Once theshutdown initiated flag 114 is set while the gate count indicates thatthere are no active virtual processors that are not idle, the schedulerproceeds to phase one shutdown.

At the start of phase one shutdown, the scheduler executes a CAS loop toset the active suspend state flag 116. This flag 116 is only set if thegate count 112 is zero. If the CAS fails because the gate count 112 haschanged, shutdown is aborted and will be reattempted the next time thegate count 112 reaches zero. If the CAS succeeds, a computing systemincluding the scheduler prevents virtual processors from performing astate transition (e.g. from idle 204 to active 206 or from inactive 202to active 206) until the flag 116 is cleared. During this time, thescheduler performs a sweep of all collections 108 and searches for anywork in the scheduler 100 (including work items that are not runnablesuch as those assigned to blocked contexts). If any work is found, thescheduler clears the suspend state flag 116, wakes any virtual processorblocked on a state transition, and rolls back shutdown. If no work isfound, the scheduler 100 proceeds to phase two of shutdown.

During phase two of shutdown, the scheduler 100 messages all contexts106 and tells them to exit. It then utilizes a CAS loop to atomicallyset the shutdown completed flag 118 and clear the active suspend stateflag 116

Once the CAS loop succeeds, the resultant gate count indicates how manyvirtual processors to awaken via that level of change to a transitionsemaphore. It then decrements a reference count 120. In the embodimentillustrated, the internal reference count 120 is the number of contextswithin the scheduler plus one. The plus one is for the thread which iscalling the final release which may not be one of the scheduler's owncontexts. When this reference count 120 falls to zero, the schedulerfinalizes and signals the client of this. In other embodiments, otherinstrumentalities may be used. In particular, the reference count 120,or other instrumentality, is used to tell when the scheduler iscompletely finalized and the memory associated with it can be released(e.g.: the C++ objects destroyed, etc). Additionally, it may be anindication that the client can be notified

State transitions of virtual processors, as illustrated in FIG. 2, mayfollow a careful set of rules to synchronize with this process at keypoints. In particular, as noted, no synchronization is performed exceptduring state transitions between active 206 to and from inactive 202,and between active 206 to and from idle 204.

When a virtual processor 104 wants to go from the inactive state 202 toactive state 206, the virtual processor 104 first checks the shutdowncompleted flag 118. If set, the activation fails. If not set, thevirtual processor 104 waits until the suspend state flag 116 in the gateis clear and then performs a CAS operation on the shutdown gate 110machine word to increment the gate count while ensuring that no agentsimultaneously manipulates the active suspend state flag 116. Waitingmay be accomplished, in one embodiment, by the virtual processor 104spin polling. The CAS operation is retried until it either succeeds orthe shutdown completed flag 114 is set.

When a virtual processor 104 wants to go from active 206 to idle 204,for example as the result of not finding work, or active 206 to inactive202, for example as the result of wanting to retire a virtual processorfrom dynamic resource management, the virtual processor 104 atomicallydecrements the shutdown gate 110 machine word, effectively decrementingthe gate count in the illustrated embodiment. If the result of thedecrement shows the gate count 112 to be zero and the shutdown initiatedflag 114 is set, the scheduler tries to CAS-set the active suspend stateflag 116. If the CAS succeeds with the gate count 112 remaining zero,phase one of shutdown occurs as described above.

When a virtual processor wants to go from an idle state 204 to an activestate 206, it atomically increments the shutdown gate 110 machine word(effectively incrementing the gate count 112). If the result of theincrement shows the active suspend state flag 116 as zero, the statetransition is allowed. If the result shows the active suspend state flag116 as non-zero, the state transition blocks on the transitionsemaphore.

If the scheduler decides to roll back shutdown due to work being foundin phase one shutdown, etc, it atomically clears the active suspendstate flag 116 via a CAS loop. Once the CAS-loop succeeds, the resultantgate count 112 is examined and the transition semaphore is released thatnumber of times to wake any blocked virtual processors so they maycomplete state changes.

The scheduler 100 may also fully roll back finalization by clearing theshutdown initiated flag 114. This may happen if, for instance, a blockedcontext which existed when the scheduler 100 started phase one shutdownunblocked, passed a pointer to the scheduler to a new thread which thentook a reference count, incrementing the reference count 102 from zeroto one and would fully roll back shutdown.

The following discussion now refers to a number of methods and methodacts that may be performed. It should be noted, that although the methodacts may be discussed in a certain order or illustrated in a flow chartas occurring in a particular order, no particular ordering isnecessarily required unless specifically stated, or required because anact is dependent on another act being completed prior to the act beingperformed.

Referring now to FIG. 3, a method 300 is illustrated. The method 300includes acts for shutting down a computer work scheduler. The workscheduler includes a number of virtual processors (e.g. virtualprocessors 104 illustrated in FIG. 1). Each virtual processor representsthe ability to execute a single thread (e.g. the contexts 106illustrated in FIG. 1). Each virtual processor is either active in thatit has a context running atop it performing at least one of executingwork, searching for work, or idle after not finding work after apredetermined amount of searching for work, or inactive in that it hasno context running atop it. The method includes determining that allprocessors in a given set of active virtual processors controlled by thescheduler are idle (act 302). In one embodiment, as illustrated above,this may be accomplished by using a data structure, such as the gatecount 112 illustrated in FIG. 1 above.

The method 300 further includes, as a result of determining that allprocessors in the given set of active virtual processors controlled bythe scheduler are idle, proceeding to a first phase 310 of a shutdownoperation. The first phase 310, when successful, includes performing asweep of all collections searching for any work in the scheduler (act304) and determining that no work is found in the scheduler (act 306).When the first phase is not successful, shutdown may be aborted. Thefirst phase may not be successful as a result of the failure of a CASoperation as described above, and as will be illustrated in examplesbelow.

As a result of determining that no work is found in the scheduler, themethod 300 proceeds to a second phase 312 of a shutdown operation, whichwhen successful includes messaging all contexts in the scheduler andtelling them to exit (act 308).

The method 300 may be practiced where the method is performed as aresult of determining that a scheduler reference count has fallen tozero. The scheduler reference count comprises a counter included in thescheduler. An example of the scheduler reference counter is illustratedat 102 in FIG. 1.

The method 300 may be practiced where the computing system includes ablock of memory, such as the shutdown gate 110. The block of memory maybe transactional shared memory. For example, in one embodiment, theblock of memory includes an atomic machine word. In the exampleillustrated in FIG. 1, a 32 bit machine word is used.

The block of memory includes a gate count portion (e.g. gate count 112)including at least a portion of the block of memory that includes acount based on the number of active virtual processors minus the numberof idle virtual processors. Determining that all processors in the givenset of active virtual processors controlled by the scheduler are idle(act 302) may include determining that the gate count portion indicatesthat all processors in the given set of active virtual processorscontrolled by the scheduler are idle.

The block of memory may also include a block of memory that can be readatomically, such as transactional memory. The block of memory mayfurther include a shutdown initiated flag (e.g. 114), an active suspendstate flag (e.g. 116), and a shutdown completed flag (e.g. 118).Proceeding to a first phase of a shutdown operation may also beperformed as a result of successfully setting the shutdown initiatedflag 114 using an atomic compare and swap operation on the block ofmemory, and detecting that the gate count 112 was zero. In theillustrated embodiment, the shutdown initiated flag 114 is always setwhen reference counter 120 falls to zero. Processing proceeds to thefirst phase if the gate count was zero at the time shutdown initiatedflag 114 was set. Thus, processing only proceeds with the first phase ofshutdown if there were zero active virtual processors at the time theshutdown initiated flag 114 is set.

The first phase of the shutdown operation may further includesuccessfully setting the active suspend state flag using an atomiccompare and swap operation on the block of memory. This ensures thatcount of the gate count portion continues to indicate that allprocessors in the given set of active virtual processors controlled bythe scheduler are idle at the conclusion of setting the active suspendstate flag. As noted, virtual processors in the work scheduler may beprevented from performing a state transition until the active suspendstate flag is cleared.

The second phase of the shutdown operation may further includesuccessfully setting the shutdown completed flag and clearing the activesuspend state flag using an atomic compare and swap operation on theblock of memory.

In some embodiments, a virtual processor may attempt to transition froman inactive to active state. In these embodiments, the virtual processorchecks the shutdown completed flag. When the shutdown completed flag isnot set, the virtual processor waits until the active suspend state flagis clear and then performs an atomic compare and swap operation toincrement the count of the gate count portion while ensuring that theactive suspend state flag is not manipulated.

In some embodiments, when a virtual processor attempts to transitionfrom an active to idle state or active to inactive state, the gate countportion is decremented. In some embodiments, when a virtual processorattempts to transition from an idle to active state, the gate countportion is incremented.

The method 300 may further include signaling a client indicating thatthe scheduler has been shut down.

Referring now to FIG. 4, an overview method figure is shown illustratingmethod steps for various actions such as virtual processor statetransitions and scheduler dereferencing. FIG. 4 will be explained withreference to FIGS. 1 and 2.

Referring now to FIG. 4, at 402 a virtual processor 104 requests goingfrom an inactive state 202 to an active state 206. At 404, adetermination is made whether or not the shutdown completed flag 118 isset. If the shutdown completed flag 118 is set, as illustrated at 406,the request to go from an inactive state 202 to an active state 206 isdenied inasmuch as the scheduler 100 is shutting down. However, if theshutdown completed flag 118 is not set, then as illustrated at 408 thevirtual processor 104 will spin poll until the suspended state flag 116is cleared. Once the suspended state flag 116 is cleared, an atomiccompare and swap loop operation is attempted to increment the gate count112 as illustrated at 410. The atomic compare and swap loop operationmay fail as a result of the suspend flag 116 being set. In this caseprocessing returns to 408 were the virtual processor continues to spinuntil the active suspend state flag 116 is cleared. The compare and swaploop operation illustrated at 410 may alternatively fail because theshutdown completed flag 118 is set. In this case, processing returns to406 wherein the request to go from an inactive state 202 to an activestate 206 is denied inasmuch as the scheduler 100 is shutting down. Theatomic compare and swap loop operation illustrated at 410 may succeed inwhich case the virtual processor 104 is active and can run work asillustrated at 412.

FIG. 4 further illustrates an action where a virtual processor goes fromidle to active as illustrated at 414. When the virtual processor 104goes from an idle state 204 to an active state 206, the gate word 110 isincremented as illustrated at 416, effectively incrementing the gatecount 112. After incrementing the gate word 110, a determination can bemade whether are not the active suspend state flag 116 is set. If theactive suspend state flag 116 is not set, then processing proceeds to412 where the virtual processor 104 is active and can run work. If theactive suspend state flag 116 is set, processing proceeds to 418 whereshutdown is blocked on a transition semaphore. Processing then proceedsto 420, after the semaphore is released, where a determination is madewhether or not a message for cancellation of shutdown has been sent. Ifno such message has been sent, then as illustrated at 412, the virtualprocessor 104 is active and can run work. If such a cancellation messagehas been made then the virtual processor 104 will prepare to exit thethread context 106 and clean up the virtual processor 104 as illustratedat 422. At 424 and internal reference counter is decremented. Theinternal reference counter 120 is count of a number related to thenumber of threads/contexts in the scheduler 100. Notably, in someembodiments, the count in the reference counter 120 may be the number ofthreads/contexts in the scheduler plus one for the thread that might becalling Release and finalizing in that thread context. If the internalreference count 120 is equal to zero then shut down is finalized and theclient is notified as illustrated at 426. If decrementing the internalreference count 120 does not result in the internal reference count 120being greater than zero, no further shutdown actions are performed atthe present time as illustrated at 428.

Reference is now directed to 430 which illustrates the process of eventswhen a virtual processor 104 goes from an active state 206 to an idlestate 204 or from an active state 206 to an inactive state 202. When thevirtual processor 104 changes state, the gate word 110 is decremented asillustrated at 432. If the resulting gate count 112 is greater than zeroor the shutdown initiated flag 114 is cleared then no further shutdownactions are performed as illustrated at 428. Alternatively, if the gatecount 112 is equal to zero and the shutdown initiated flag 114 is set,then processing proceeds to 434 wherein an atomic compare and swap loopis attempted to set the active suspend state flag 116. If the atomiccompare and swap loop operation fails due to the gate count 112 beinggreater than zero, then no further shutdown actions are performed at thepresent time as illustrated at 428. However, if the atomic compare andswap loop operation setting the suspend state active suspend state flag116 succeeds, then processing proceeds to 436 wherein operationssweeping the scheduler 100 for work are performed. If work is foundduring the sweep operation, then the active suspend state flag 116 iscleared, and the gate count 112 is used to wake a number of virtualprocessors 104 as indicated by the gate count 112 using the transitionsemaphore as illustrated at 438, whereafter no further shutdown actionsare performed at the present time as illustrated at 428. However, if nowork is found, phase two shutdown is begun whereafter the shutdowncompleted flag 118 is set, one or more cancellation messages are sentdirecting all virtual processors to shut down, and all virtualprocessors are woken so as to initiate shutdown of the virtualprocessors 104 as illustrated at 440. Processing proceeds todecrementing the internal reference count 120 and a determination ismade of the result of the internal reference count so as to determinewhether or not finalization and client notification should occur asillustrated at 426 or not performing any further shutdown actions asillustrated at 428.

FIG. 4 further illustrates operations performed when dereferencing ascheduler as indicated at 442. In particular, the scheduler 100 includesa list of work items to be performed. Dereferencing the scheduler,results in an action of determining whether or not the reference countis zero or not at 444. If the reference count is not zero, then nofurther shutdown actions are performed as of yet as illustrated at 428.If the reference count is zero, then an atomic compare-and-swap loopoperation is performed to set the shutdown initiated flag 114 asillustrated at 446. If the gate count 112 is greater than zero afterperforming the atomic compare-and-swap loop operation on the shutdowngate 110, then no further shutdown actions are performed at the presenttime is illustrated at 428. However, if the gate count 112 is equal tozero after the atomic compare-and-swap loop operation setting theshutdown initiated flag 114, then further shut down operations may beattempted as previously discussed at 434, 436, 440, 424, 426, 438, and428 as illustrated in FIG. 4.

Embodiments of the present invention may comprise or utilize a specialpurpose or general-purpose computer including computer hardware, asdiscussed in greater detail below. Embodiments within the scope of thepresent invention also include physical and other computer-readablemedia for carrying or storing computer-executable instructions and/ordata structures. Such computer-readable media can be any available mediathat can be accessed by a general purpose or special purpose computersystem. Computer-readable media that store computer-executableinstructions are physical storage media. Computer-readable media thatcarry computer-executable instructions are transmission media. Thus, byway of example, and not limitation, embodiments of the invention cancomprise at least two distinctly different kinds of computer-readablemedia: physical storage media and transmission media.

Physical storage media includes RAM, ROM, EEPROM, CD-ROM or otheroptical disk storage, magnetic disk storage or other magnetic storagedevices, or any other medium which can be used to store desired programcode means in the form of computer-executable instructions or datastructures and which can be accessed by a general purpose or specialpurpose computer.

A network is defined as one or more data links that enable the transportof electronic data between computer systems and/or modules and/or otherelectronic devices. When information is transferred or provided over anetwork or another communications connection (either hardwired,wireless, or a combination of hardwired or wireless) to a computer, thecomputer properly views the connection as a transmission medium.Transmissions media can include a network and/or data links which can beused to carry or desired program code means in the form ofcomputer-executable instructions or data structures and which can beaccessed by a general purpose or special purpose computer. Combinationsof the above should also be included within the scope ofcomputer-readable media.

Further, upon reaching various computer system components, program codemeans in the form of computer-executable instructions or data structurescan be transferred automatically from transmission media to physicalstorage media (or vice versa). For example, computer-executableinstructions or data structures received over a network or data link canbe buffered in RAM within a network interface module (e.g., a NIC), andthen eventually transferred to computer system RAM and/or to lessvolatile physical storage media at a computer system. Thus, it should beunderstood that physical storage media can be included in computersystem components that also (or even primarily) utilize transmissionmedia.

Computer-executable instructions comprise, for example, instructions anddata which cause a general purpose computer, special purpose computer,or special purpose processing device to perform a certain function orgroup of functions. The computer executable instructions may be, forexample, binaries, intermediate format instructions such as assemblylanguage, or even source code. Although the subject matter has beendescribed in language specific to structural features and/ormethodological acts, it is to be understood that the subject matterdefined in the appended claims is not necessarily limited to thedescribed features or acts described above. Rather, the describedfeatures and acts are disclosed as example forms of implementing theclaims.

Those skilled in the art will appreciate that the invention may bepracticed in network computing environments with many types of computersystem configurations, including, personal computers, desktop computers,laptop computers, message processors, hand-held devices, multi-processorsystems, microprocessor-based or programmable consumer electronics,network PCs, minicomputers, mainframe computers, mobile telephones,PDAs, pagers, routers, switches, and the like. The invention may also bepracticed in distributed system environments where local and remotecomputer systems, which are linked (either by hardwired data links,wireless data links, or by a combination of hardwired and wireless datalinks) through a network, both perform tasks. In a distributed systemenvironment, program modules may be located in both local and remotememory storage devices.

The present invention may be embodied in other specific forms withoutdeparting from its spirit or essential characteristics. The describedembodiments are to be considered in all respects only as illustrativeand not restrictive. The scope of the invention is, therefore, indicatedby the appended claims rather than by the foregoing description. Allchanges which come within the meaning and range of equivalency of theclaims are to be embraced within their scope.

1. In a computing system, a method of shutting down a computer workscheduler, the work scheduler comprising a number of virtual processors,each representing the ability to execute a single thread, wherein eachvirtual processor is either active in that it has a context running atopit performing at least one of executing work, searching for work, oridle after not finding work after a predetermined amount of searchingfor work, or inactive in that it has no context running atop it, themethod comprising: determining that all processors in a given set ofactive virtual processors controlled by the scheduler are idle; as aresult of determining that all processors in the given set of activevirtual processors controlled by the scheduler are idle, proceeding to afirst phase of a shutdown operation, which when successful, includes:performing a sweep of all collections searching for any work in thescheduler; and determining that no work is found in the scheduler; andas a result of determining that no work is found in the schedulerproceeding to a second phase of the shutdown operation, which whensuccessful includes messaging all contexts in the scheduler and tellingthem to exit the scheduler.
 2. The method of claim 1, wherein the methodis performed as a result of determining that a scheduler reference counthas fallen to zero, wherein the scheduler reference count comprises acontext counter included in the scheduler wherein the context counterincludes a count related to the number of contexts in the scheduler. 3.The method of claim 1, wherein the computing system comprises a block ofmemory, wherein the block of memory includes a gate count portionincluding at least a portion of the block of memory that comprises acount based on the number of active virtual processors minus the numberof idle virtual processors, and wherein determining that all processorsin the given set of active virtual processors controlled by thescheduler are idle comprises determining that the gate count portionindicates that all processors in the given set of active virtualprocessors controlled by the scheduler are idle.
 4. The method of claim3, wherein the block of memory comprises a block of memory that can beread atomically, and wherein the block of memory further comprises ashutdown initiated flag, an active suspend state flag, and a shutdowncompleted flag, wherein: proceeding to the first phase of the shutdownoperation is also performed as a result of successfully setting theshutdown initiated flag using an atomic compare and swap operation onthe block of memory and detecting that the gate count portion is zero;wherein the first phase of the shutdown operation further comprisessuccessfully setting the active suspend state flag using an atomiccompare and swap operation on the block of memory, which ensures thatcount of the gate count portion continues to indicate that allprocessors in the given set of active virtual processors controlled bythe scheduler are idle at the conclusion of setting the active suspendstate flag, and wherein virtual processors in the work scheduler areprevented from performing a state transition until the active suspendstate flag is cleared; and wherein the second phase of the shutdownoperation further comprises successfully setting the shutdown completedflag and clearing the active suspend state flag using the atomic compareand swap operation on the block of memory.
 5. The method of claim 4,wherein the block of memory comprises an atomic machine word.
 6. Themethod of claim 4, further comprising a virtual processor attempting totransition from an inactive to active state comprising: checking theshutdown completed flag, and when the shutdown completed flag is notset, waiting until the active suspend state flag is clear and thenperforming an atomic compare and swap operation to increment the countof the gate count portion while ensuring that the active suspend stateflag is not manipulated.
 7. The method of claim 4, further comprising avirtual processor attempting to transition from an active to idle stateor active to inactive state comprising decrementing the gate countportion.
 8. The method of claim 4, further comprising a virtualprocessor attempting to transition from an idle to active statecomprising incrementing the gate count portion.
 9. The method of claim1, further comprising signaling a client indicating that the schedulerhas been shut down.
 10. A computing system including functionality forshutting down a computer work scheduler, the work scheduler comprising anumber of virtual processors, each representing the ability to execute asingle thread, wherein each virtual processor is either active in thatit has a context running atop it performing at least one of executingwork, searching for work, or idle after not finding work after apredetermined amount of searching for work, or inactive in that it hasno context running atop it, the system comprising: a computer modulethat determines that virtual processors in a given set of active virtualprocessors controlled by the scheduler are idle; a computer module thatas a result of determining that all processors in the given set ofactive virtual processors controlled by the scheduler are idle,:performs a sweep of all collections searching for any work in thescheduler; and determines that no work is found in the scheduler; and acomputer module that, as a result of determining that no work is foundin the scheduler messages all contexts in the scheduler and tells themto exit the scheduler.
 11. The computing system of claim 10, wherein:the computing system further comprises a block of memory, wherein theblock of memory: includes a gate count portion including at least aportion of the block of memory that comprises a count based on thenumber of active virtual processors minus the number of idle virtualprocessors; can be read atomically, and wherein the block of memoryfurther comprises a shutdown initiated flag, an active suspend stateflag, and a shutdown completed flag, the computing system furthercomprises a module that successfully sets the active suspend state flagusing an atomic compare and swap operation on the block of memory, whichensures that count of the gate count portion continues to indicate thatall processors in the given set of active virtual processors controlledby the scheduler are idle at the conclusion of setting the activesuspend state flag, and wherein virtual processors in the work schedulerare prevented from performing a state transition until the activesuspend state flag is cleared; and the computing system furthercomprises a module that successfully sets the shutdown completed flagand clearing the active suspend state flag using the atomic compare andswap operation on the block of memory.
 12. The computing system of claim11, further comprising a computer module that prevents state transitionsof virtual processors when the active suspend state flag is set.
 13. Thecomputing system of claim 11, further comprising one or more computermodules that: atomically attempt to set the active suspend state flag;determine that atomically attempting to set the active suspend stateflag has failed because all processors in the given set of activevirtual processors controlled by the scheduler are not idle at theconclusion of atomically attempting to set the active suspend stateflag; and as a result of determining that atomically attempting to setthe active suspend state flag has failed because all processors in thegiven set of active virtual processors controlled by the scheduler arenot idle at the conclusion of atomically attempting to set the activesuspend state flag, abort shutting down the work scheduler.
 14. Thecomputing system of claim 11, further comprising one or more computermodules that: atomically set the active suspend state flag; perform asweep of all collections searching for any work in the scheduler; andfind work in the scheduler; and as a result of finding work in thescheduler, clear the active suspend state flag, waking any virtualprocessors blocked on a state transition and rolling back shutting downthe work scheduler.
 15. The computing system of claim 10, furthercomprising a computer module that is configured to roll back shutdown.16. In a computing environment, a method of shutting down a computerwork scheduler, the work scheduler comprising a number of virtualprocessors, each representing the ability to execute a single thread,wherein each virtual processor is either active in that it has a contextrunning atop it performing at least one of executing work, searching forwork, or idle after not finding work after a predetermined amount ofsearching for work, or inactive in that it has no context running atopit, the method comprising: determining that all processors in a givenset of active virtual processors controlled by the scheduler are idle;as a result of determining that all processors in the given set ofactive virtual processors controlled by the scheduler are idle,atomically setting a shutdown initiated flag; determining that at thetime atomically setting the shutdown initiated flag succeeds that allprocessors in the given set of active virtual processors controlled bythe scheduler are idle; as a result of determining that at the timeatomically setting the shutdown initiated flag succeeds that allprocessors in the given set of active virtual processors controlled bythe scheduler are idle, proceeding to a first phase of a shutdownoperation, which when successful, includes: atomically setting a activesuspend state flag; performing a sweep of all collections searching forany work in the scheduler; and determining that no work is found in thescheduler; as a result of determining that no work is found in thescheduler proceeding to a second phase of the shutdown operation, whichwhen successful includes: messaging all contexts and telling them toexit the scheduler; atomically setting a shutdown completed flag; andatomically clearing the active suspend state flag.
 17. The method ofclaim 16, wherein the virtual processors are prevented from performing astate transition after the act of atomically setting an active suspendstate flag until the active suspend state flag is cleared.
 18. Themethod of claim 16, wherein determining that a given set of activevirtual processors controlled by the scheduler are idle comprisesreferencing a gate count calculated by subtracting a number of idlevirtual processor from a number of active virtual processors.
 19. Themethod of claim 16, further comprising as a result of determining thatat the time atomically setting a shutdown initiated flag succeeds thatall processors in the given set of active virtual processors controlledby the scheduler are idle, proceeding to a first phase of a shutdownoperation, which when unsuccessful includes: atomically attempting toset an active suspend state flag; determining that atomically attemptingto set an active suspend state flag has failed because all processors inthe given set of active virtual processors controlled by the schedulerare not idle at the conclusion of atomically attempting to set an activesuspend state flag; and as a result of determining that atomicallyattempting to set an active suspend state flag has failed because allprocessors in the given set of active virtual processors controlled bythe scheduler are not idle at the conclusion of atomically attempting toset an active suspend state flag, aborting shutting down the workscheduler.
 20. The method of claim 16, further comprising as a result ofdetermining that at the time atomically setting a shutdown initiatedflag succeeds that all processors in the given set of active virtualprocessors controlled by the scheduler are idle, proceeding to a firstphase of a shutdown operation, which when rolled back includes:atomically setting an active suspend state flag; performing a sweep ofall collections searching for any work in the scheduler; and findingwork in the scheduler; and as a result of finding work in the scheduler,clearing the active suspend state flag, waking any virtual processorsblocked on a state transition and rolling back shutting down the workscheduler.